#include <iostream>

#include "SDL/SDL.h"
#include "SDL/SDL_net.h"
#include "SDL/SDL_thread.h"

#include "server.h"

void cleanup();

int main(int argc, char** argv)
{
	freopen( "CON", "wt", stdout );
	
    atexit(cleanup);
	
	if (SDLNet_Init() < 0) {
		fprintf(stderr, "SDLNet_Init: %s\n", SDLNet_GetError());
		exit(1);
	}
	
	Server server;
	
	SDL_Thread* main_thread;
	SDL_Thread* secondary_thread;
	
	main_thread	= SDL_CreateThread(Server::main_loop_run,(void*)&server);
	secondary_thread = SDL_CreateThread(Server::secondary_loop_run,(void*)&server);	
	
	SDL_WaitThread(main_thread, NULL);
	SDL_WaitThread(secondary_thread,NULL);
	
    return 0;
}

void cleanup()
{
    SDL_Quit();
}
